package design.patterns.templatemethod;

/**
 * @Desc:   抽象类
 * @author: cww
 * @DateTime: 2020-06-11 22:07
 */

abstract public class Account {
    protected String accountNumber = null;

    public Account() {
    }

    public Account(String accountNumber) {
        this.accountNumber = accountNumber;
    }


    /**
     * 模板方法计算利息数额，顶级逻辑骨架内容
     *
     * @return
     */
    final public double calculateInterest() {
        double interestRate = doCalculateInterestRate();
        String accountType = doCalculateAccountType();
        double amount = calculateAmount(accountType, accountNumber);
        return amount * interestRate;
    }

    /**
     * 基本方法留给子类实现
     * @return
     */
    abstract protected String doCalculateAccountType();

    /**
     * 基本方法留给子类实现
     * @return
     */
    abstract protected double doCalculateInterestRate();

    /**
     * 基本方法，已经实现
     * @param accountType
     * @param accountNumber
     * @return
     */
    final public double calculateAmount(String accountType, String accountNumber){
        // 假设从数据库查回来余额
        return 7243.00D;
    }
}
